import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xin_he/page/mine/xin_he_mine/x_in_he_my_favor/xin_he_my_favor_item_entity.dart';

import '../../../../utils/xh_styles.dart';
import '../../../../utils/xin_he_image.dart';
import '../../../shopping_car/models/xin_he_goods_model.dart';
import 'x_in_he_my_favor_logic.dart';

class XInHeMyFavorPage extends StatelessWidget {
  XInHeMyFavorPage({Key? key}) : super(key: key);

  final logic = Get.put(XInHeMyFavorLogic());
  final state = Get.find<XInHeMyFavorLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Obx(() => Scaffold(
      appBar: AppBar(
        leading: IconButton(
            onPressed: (){
              Get.back();
            },
            icon: Container(
              padding: const EdgeInsets.only(left: 7),
              alignment: Alignment.centerLeft,
              child: const XinHeAssetImage(
                'assets/images/home/app_back_3.png',
                width: 9.5,
                height: 17,
                fit: BoxFit.cover,),
            )
        ),
        backgroundColor: Colors.white,
        shadowColor: Colors.transparent,
        title: Text('我的收藏',style: TextStyle(color:XinHeColor('#222222'),fontSize: 17,fontWeight: FontWeight.w600)),
        centerTitle: true,
      ),
      body:  state.list.length>0?  ListView.builder(
          itemCount: state.list.length,
          itemBuilder: (ctx,index){
            XinHeMyFavorItemEntity model = state.list[index];

            return  Container(
              margin: const EdgeInsets.symmetric(horizontal: 15).copyWith(bottom: 10),
              padding: const EdgeInsets.symmetric(horizontal: 15),
              decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.circular(7)),

              child: Column(
                children: [
                  SizedBox(
                    height: 44,
                    child: Row(children: [
                      const XinHeAssetImage('assets/images/cart/cart_unselected.png',width: 18,height: 18,),
                      SizedBox(width: 5,),
                      Text(model.sellerName??'',style: TextStyle(color: XinHeColor('#282C2C'),fontSize: 13,fontWeight: FontWeight.w500),),
                      SizedBox(width: 3,),
                      const XinHeAssetImage('assets/images/cart/pay_arrow.png',width: 6,height: 10,),
                      Spacer(),


                    ],),
                  ),

                  ListView.builder(
                     physics: const NeverScrollableScrollPhysics(),
                      shrinkWrap: true,
                      itemCount: model.goodsCollectViews?.length,
                      itemBuilder: (ctx,ind){
                       XinHeMyFavorItemGoodsCollectViews item = model.goodsCollectViews![ind];
                    return _goodsItemView(item, ind);
                  }),
                  const SizedBox(height: 5,)


                ],),);
          }): Center(child: Text('暂无数据'),) ,

    ));
  }

  Widget _goodsItemView(XinHeMyFavorItemGoodsCollectViews model,int index){
    return Stack(
      children: [
        Container(
          color: Colors.white,
          width: Get.width-30,
          height: 90,

          child:  Row(
            children: [

               Padding(
                padding:  const EdgeInsets.only(left: 0,top: 0,right: 15,bottom: 10),
                child: XinHeNetImage(url:model.iconPath!,width: 80,height: 80,fit: BoxFit.fill,),
              ),

              ///描述与价格数量
              Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  SizedBox(
                      width:Get.width-30-80-30-15,
                      child: Text(model.name??'',maxLines: 2,softWrap: true,style: TextStyle(color: XinHeColor('#222222'),fontSize: 14,fontWeight: FontWeight.bold),)
                  ),
                  const SizedBox(height: 10,),



                  SizedBox(
                    width:Get.width-30-80-30-15,
                    height: 23,
                    child: Row(
                      children: [

                        RichText(
                            text: TextSpan(children: [
                              ///￥
                              TextSpan(
                                text: '￥',
                                style: TextStyle(
                                  color: XinHeColor('#E84128'),
                                  fontSize: 9,
                                  fontWeight: FontWeight.w500,
                                ),
                              ),

                              ///
                              TextSpan(
                                text: '${model.price}',
                                style: TextStyle(
                                  color: XinHeColor('#E84128'),
                                  fontSize: 16,
                                  fontWeight: FontWeight.w500,
                                ),
                              ),

                            ]
                            )),
                        const Spacer(),

                        Text('删除',style: TextStyle(color: XinHeColor('#8B9191'), fontSize: 12, fontWeight: FontWeight.w500,)
                        ),
                        const SizedBox(width: 0,)

                      ],
                    ),
                  )

                ],)


            ],
          ),
        ),

        // Positioned(
        //   bottom: 0,
        //   right: 15,
        //   child: Container(
        //     width: Get.width-30-30,
        //     color: XinHeColor('#E7EEEE'),
        //     height: 0.5,),
        // )

      ],
    );
  }

}
